home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / VGADRV.H < prev    next >
C/C++ Source or Header  |  1992-09-09  |  13KB  |  340 lines

  1. /* VGADRV.H (VGA-level)        SCREEN library
  2.  * Description:
  3.  *      VGA mode 13h defines and macros.
  4.  * Portability: BORLANDC
  5.  * $Header: egadrv.h,v 1.2 91/06/02 16:09:07 erdy Exp $
  6.  *                Copyright (c)   erdy 1992
  7.  */
  8. #ifndef _VGADRV_H_
  9. #       define _VGADRV_H_
  10. /*
  11.  * Keys to grswitch:
  12.  */
  13. #define GRSWITCH_EXIT 0
  14. #define GRSWITCH_SOFF 0x10                   /* Disable refreshing */
  15. #define GRSWITCH_CMODE 0x20                  /* Switch to chained mode */
  16. #define GRSWITCH_UMODE 0x40                  /* Switch to unchained mode */
  17.  
  18. #define SCMODE_CHAINED    0
  19. #define SCMODE_UNCHAINED  1
  20.  
  21. extern struct Svideo {
  22.         char     aname[8];              /* ê¼∩ áñá»ΓÑαá                  */
  23.         unsigned int page_seg[4];
  24.         unsigned int vpage;             /* é¿ñ¿¼á∩ ßΓαá¡¿µá    */
  25.         unsigned int opage;             /* æΓαá¡¿µá ñ½∩ óδó«ñá */
  26.         union saddress {
  27.         unsigned int w;
  28.         char b[2];
  29.         } saddress[2];
  30.     union saddress top;
  31.         int      oldmode;      /* ÉѪ¿¼ αáí«Γδ áñá»ΓÑαá         */
  32. } Sadapter;
  33.  
  34. /* MCGA CHAINED/UNCHAINED mode settings:
  35.  * -------------------------------------
  36.  */
  37.  
  38. #if defined(VGA_DUALMODE) && !defined(VGA_UNCHAINED)
  39. #       define VGA_UNCHAINED
  40. #endif
  41.  
  42. /* MCGA Common settings: */
  43. #define VGA_RAM ((char far *)0xA0000000)   /* VGA Video RAM address  */
  44. #define VGA_RAMSIZE 0x10000                /* Size of RAM, as mapped to host */
  45. #define VGA_SEG0 0xA000                    /* Segment address of VRAM */
  46. #define PPERBYTE 1                         /* Pixels per byte */
  47. #define BITPLANES 4
  48. #define MAXROWS 200
  49. #define MAXCOLS 320
  50. #define MAXCOLORS 256
  51. #define MAXCOLORCODE 63
  52. #define BPERDCOLOR 3                            /* Byte per direct color code */
  53. #define PALETTESIZE (MAXCOLORS*BPERDCOLOR)
  54. #define ASP_RATIO  0.7
  55. #define ASP_RATIO_NUMERATOR  7
  56. #define ASP_RATIO_DENOMINATOR 10
  57.  
  58. /* MCGA ChainFourOn (standard) mode settings: */
  59. #define MAXPAGES_CHAINED 1
  60. #define VGA_SEG1_CHAINED 0xAFA0
  61. #define VGA_PSIZE_CHAINED 0xFA00           /* = 64000. Graphic Page length */
  62. #define BPERROW_CHAINED 320                /* Bytes per scanline */
  63. #define BPERSCREEN_CHAINED 320
  64.  
  65. /* MCGA ChainFourOff mode settings: */
  66. #define MAXPAGES_UNCHAINED  4
  67. #define VGA_SEG1_UNCHAINED 0xA3E8
  68. #define VGA_SEG2_UNCHAINED 0xA7D0
  69. #define VGA_SEG3_UNCHAINED 0xABB8
  70. #define VGA_PSIZE_UNCHAINED 0x3E80          /* =16000. Graphic Page length */
  71. #define BPERROW_UNCHAINED 80                /* Bytes per scanline */
  72. #define BPERSCREEN_UNCHAINED 80
  73.  
  74. #ifdef VGA_UNCHAINED
  75. #       ifndef BPERROW
  76. #               define BPERROW BPERROW_UNCHAINED
  77. #       else  BPERROW
  78. #               define VGA_BPERROW
  79. #       endif BPERROW
  80. #       define BPERSCREEN BPERSCREEN_UNCHAINED
  81. #       define MAXPAGES MAXPAGES_UNCHAINED
  82. #       define VGA_SEG1 VGA_SEG1_UNCHAINED
  83. #       define VGA_SEG2 VGA_SEG2_UNCHAINED
  84. #       define VGA_SEG3 VGA_SEG3_UNCHAINED
  85. #       define VGA_PSIZE VGA_PSIZE_UNCHAINED
  86. #else  VGA_UNCHAINED
  87. #       ifndef BPERROW
  88. #               undef BPERROW
  89. #               define BPERROW BPERROW_CHAINED
  90. #       endif BPERROW
  91. #       define BPERSCREEN BPERSCREEN_CHAINED
  92. #       define MAXPAGES MAXPAGES_CHAINED
  93. #       define VGA_SEG1 VGA_SEG1_CHAINED
  94. #       define VGA_SEG2 VGA_SEG1_CHAINED
  95. #       define VGA_SEG3 VGA_SEG1_CHAINED
  96. #       define VGA_PSIZE VGA_PSIZE_CHAINED
  97. #endif VGA_UNCHAINED
  98.  
  99. #define VIDEO_UYTOADDRESS(y) (y*BPERROW)
  100. #define VIDEO_CYTOADDRESS(y) (y*BPERROW_CHAINED)
  101. #define VIDEO_UXTOADDRESS(x) (x>>2)
  102. #define VIDEO_CXTOADDRESS(x) x
  103. #define VIDEO_UADDRESS(x, y) (VIDEO_UXTOADDRESS(x)+VIDEO_UYTOADDRESS(y))
  104. #define VIDEO_CADDRESS(x, y) (VIDEO_CXTOADDRESS(x)+VIDEO_CYTOADDRESS(y))
  105. #ifdef VGA_DUALMODE
  106. #       define VIDEO_ADDRESS(x, y) \
  107.         (Scmode == SCMODE_CHAINED)? VIDEO_CADDRESS(x, y):VIDEO_UADDRESS(x,y)
  108. #elif defined(VGA_UNCHAINED)
  109. #       define VIDEO_ADDRESS(x, y) VIDEO_UADDRESS(x, y)
  110. #else  VGA_UNCHAINED
  111. #       define VIDEO_ADDRESS(x, y) VIDEO_CADDRESS(x, y)
  112. #endif
  113.  
  114. #define _DefaultRMode READMODE0
  115. #define _DefaultWMode WRITEMODE0
  116. #define _setDefaultRWModes()
  117.  
  118.  
  119. /*
  120.  * Hardware macros:
  121.  * ----------------
  122.  */
  123. #define VGA_CRTC_ADR  0x3D4          /* CRT Controller, Address Register */
  124. #define VGA_CRTC_GATE 0x3D5          /* CRT Controller, Index/Data Register */
  125. #       define _CRT_OVERFLOW     7
  126. #       define _CRT_MAXSCANLINE  9
  127. #       define _CRT_CURSOR_START 10
  128. #       define _CRT_CURSOR_STOP  11
  129. #       define _CRT_STARTAD_HIGH 12
  130. #       define _CRT_STARTAD_LOW  13
  131. #       define _CRT_CURPOS_HIGH  14
  132. #       define _CRT_CURPOS_LOW   15
  133. #    define _CRT_LINECOMPARE  0x18
  134. #       define _CURSOR_OFF 0360
  135. #define VGA_ATC  0x3C0       /* Attribute Controller Registers, Addr. reg.  */
  136. #define VGA_GADR 0x3CE       /* Graphic Controller Registers, Addr. reg.    */
  137. #define VGA_GCD  0x3CF       /* Graphic Controller Registers, Data reg.     */
  138. #       define _GCD_SETRES 0 /* óδí«α αÑú¿ßΓαá ßíα«ßá/πßΓᡫ󬿠GCD   */
  139. #       define _GCD_ENSET  1 /* óδí«α αÑú¿ßΓαá αáºαÑΦÑ¡¿∩ ßíα/πßΓ. GCD*/
  140. #       define _GCD_CCOMPARE 2 /* óδí«α αÑú¿ßΓαá ßαáó¡Ñ¡¿∩ µóÑΓ«ó  GCD*/
  141. #       define _GCD_ROTATE 3 /* óδí«α αÑú¿ßΓαá óαáΘÑ¡¿∩      GCD      */
  142. #       define _GCD_MAPSEL 4 /* óδí«α óδí«αá ¬áαΓδ                    */
  143. #       define _GCD_MODES  5 /* óδí«α αÑú¿ßΓαá αѪ¿¼«ó GCD            */
  144. #       define _GCD_DONTCARE 7 /* óδí«α αÑú¿ßΓαá íѺαẽ¿τ¿∩ µóÑΓá    */
  145. #       define _GCD_BITMASK  8 /* óδí«α αÑú¿ßΓαá í¿Γ«ó«⌐ ¼á߬¿ GCD    */
  146.                              /* ÉѪ¿¼δ ºá»¿ß¿ ¿ τΓÑ¡¿∩:               */
  147. #              define WRITEMODE0 0
  148. #              define WRITEMODE1 1
  149. #              define WRITEMODE2 2
  150. #              define WRITEMODE3 3
  151. #              define WRITEMODEMASK 3
  152. #              define READMODE0 0
  153. #              define READMODE1 010
  154. #              define READMODEMASK 010
  155. #define AND_LOGIC 010
  156. #define XOR_LOGIC 030
  157. #define OR_LOGIC  020
  158.  
  159. #define VGA_SER_ADR   0x3C4 /* Sequencer Registers, Addr. reg. */
  160. #define VGA_SER_GATE  0x3C5 /* Sequencer Registers, Data. reg. */
  161. #       define _SER_CM_RESET 0
  162. #       define _SER_CM_REG   1  /* Clocking Mode register */
  163. #       define _SER_MAPMASK  2  /* Map Mask register */
  164. #       define _SER_MM_REG   4  /* Memory Mode register */
  165. #define _SER_CM_SO 0x20      /* 0 - Screen on, 1 - off */
  166. #define _SER_CM_S4 0x10      /* Shift Four */
  167. #define _SER_CM_DC 0x8       /* Dot clock */
  168. #define _SER_CM_SL 0x4       /* Shift Load */
  169. #define _SER_CM_BW 0x2       /* BW */
  170. #define _SER_CM_89 0x1       /* 8/9 */
  171. #define _SER_MM_C4 0x8       /* 1-Planes Chained, 0-Planes are to be selected */
  172. #define VGA_PEL_WA 0x3c8        /* PEL address Write Mode register */
  173. #define VGA_PEL_RA 0x3c7        /* PEL address Read Mode register */
  174. #define VGA_PEL_DATA 0x3c9      /* PEL address Data register */
  175. #define VGA_PEL_STA 0x3c7       /* DAC state */
  176. #define VGA_PEL_MASK 0x3c6      /* PEL Mask register */
  177.  
  178. #define VGA_IS1  0x3DA /* Read: Input status # 1 */
  179. #define VGA_STA  0x3DA /* Write: Feature Control 0 ¿½¿ 1 */
  180.  
  181. #define VGA_RETRACE  1 /* êñÑΓ ú«α¿º«¡Γá½∞¡δ⌐ ¿½¿ óÑαΓ¿¬á½∞¡δ⌐ retrace */
  182. #define VGA_HRETRACE 1 /* êñÑΓ ú«α¿º«¡Γá½∞¡δ⌐ retrace */
  183. #define VGA_VRETRACE 8 /* êñÑΓ óÑαΓ¿¬á½∞¡δ⌐ retrace */
  184.  
  185.  
  186. #ifdef __TURBOC__
  187.  
  188. #define _chain4Off() asm {\
  189.         mov dx, VGA_SER_ADR;\
  190.         mov ax, 0x0604;\
  191.         out dx, ax;\
  192.         mov dx, VGA_CRTC_ADR;\
  193.         mov ax, 0x0014;\
  194.         out dx, ax;\
  195.         mov ax, 0xE317;\
  196.         out dx, ax;}
  197.  
  198. #define _chain4On() asm {\
  199.         mov dx, VGA_SER_ADR;\
  200.     mov ax, 0x0E04;                /* SER/MM/[C4] 0xE on */\
  201.     out dx, ax;\
  202.     mov dx, VGA_CRTC_ADR;\
  203.     mov ax, 0x4014;                /* CRTC/UL/[DW] 0x40 on */\
  204.     out dx, ax;\
  205.     mov ax, 0xA317;                /* CRTC/MC/[W/B] off */\
  206.         out dx, ax;}
  207.  
  208. #define _screenOff() \
  209.         {asm mov dx, VGA_SER_ADR;asm mov al,_SER_CM_REG;asm out dx, al;\
  210.         asm inc dx;asm in al, dx;\
  211.         asm or al,_SER_CM_SO;asm out dx, al;}
  212.  
  213. #define _screenOn() \
  214.         {asm mov dx, VGA_SER_ADR;asm mov al,_SER_CM_REG;asm out dx, al;\
  215.         asm